import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'normalize.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import vue3PreviewImage from 'vue3-preview-image'
import registerDirectives from '@/directives/index.js'
import { setupStore } from '@/store/index.js'

import './styles/index.css'
import App from './App.vue'
import router from './router'
import store from './store'

const app = createApp(App)

// 循环注册 icon 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// 注册全局指令
registerDirectives(app)

app.use(ElementPlus)
app.use(vue3PreviewImage) // 图片预览

// 顺序不能乱： 挂载store -> 刷新获取数据 -> 重新挂载路由
app.use(store)

setupStore()  // 用户刷新页面，将本地的数据赋值给 store

app.use(router)

app.mount('#app')


